package com.lianxian.xindong.life.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.iarcuschin.simpleratingbar.SimpleRatingBar;
import com.lianxian.xindong.life.R;
import com.lianxian.xindong.life.R2;
import com.lianxian.xindong.life.entities.MeiShiRecyclerModel;
import com.lianxian.xindong.life.util.GlideUtil;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

public class MeiShiRecyclerViewAdapter extends RecyclerView.Adapter {
    Context context;
    List<MeiShiRecyclerModel> list;

    public MeiShiRecyclerViewAdapter(Context context,List<MeiShiRecyclerModel> list) {
        this.context = context;
        this.list = list;
    }

    @NonNull
    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        LayoutInflater layoutInflater = LayoutInflater.from(parent.getContext());
        View view = layoutInflater.inflate(R.layout.life_item_shop, parent, false);
        ViewHolder viewHolder = new ViewHolder(view);
        return viewHolder;
    }

    @Override
    public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int position) {
        MeiShiRecyclerModel data = list.get(position);
        ViewHolder viewHolder = (ViewHolder) holder;
        viewHolder.simpleRatingBar.setRating(data.getScore());
        viewHolder.scoreTV.setText(data.getScore()+"分");
        viewHolder.distanceTV.setText("<"+data.getDistance()+"m");
        GlideUtil.GlideWithPlaceHolder(context, data.getPicUrl()).into(viewHolder.picIV);
        viewHolder.oneCommentTV.setText(data.getOneComment());
        viewHolder.lablesTV.setText(data.getLables());
        viewHolder.commentCountTV.setText(data.getCommentCount()+"条");
        viewHolder.titleTV.setText(data.getTitle());
        GlideUtil.GlideWithPlaceHolder(context, data.getPicUrl()).into(viewHolder.headPicIV);
        viewHolder.priceTV.setText("¥ "+data.getPrice());
        viewHolder.discountTV.setText(data.getDiscount()+"折");
        viewHolder.descTV.setText(data.getDesc());

    }

    @Override
    public int getItemCount() {
        return list.size();
    }
    class ViewHolder extends RecyclerView.ViewHolder {
        @BindView(R2.id.shop_Image)
        ImageView picIV;
        @BindView(R2.id.shop_name)

        TextView titleTV;
        @BindView(R2.id.ratingbar)
        SimpleRatingBar simpleRatingBar;
        @BindView(R2.id.rate_score)
        TextView scoreTV;
        @BindView(R2.id.comment_count)
        TextView commentCountTV;
        @BindView(R2.id.shop_lables)
        TextView lablesTV;
        @BindView(R2.id.shop_distance)
        TextView distanceTV;
        @BindView(R2.id.one_comment_text)
        TextView oneCommentTV;
        @BindView(R2.id.comment_head_pic)

        ImageView headPicIV;
        @BindView(R2.id.price)
        TextView priceTV;
        @BindView(R2.id.discount)
        TextView discountTV;
        @BindView(R2.id.desc)
        TextView descTV;


        public ViewHolder(@NonNull View itemView) {
            super(itemView);
            ButterKnife.bind(this,itemView);
//            picIV = itemView.findViewById(R.id.shop_Image);
//            titleTV = itemView.findViewById(R.id.shop_name);
//            simpleRatingBar = itemView.findViewById(R.id.ratingbar);
//            scoreTV = itemView.findViewById(R.id.rate_score);
//            commentCountTV = itemView.findViewById(R.id.comment_count);
//            lablesTV = itemView.findViewById(R.id.shop_lables);
//            distanceTV = itemView.findViewById(R.id.shop_distance);
//            oneCommentTV=itemView.findViewById(R.id.one_comment_text);
//            headPicIV  =itemView.findViewById(R.id.comment_head_pic);
//            priceTV = itemView.findViewById(R.id.price);
//            discountTV=itemView.findViewById(R.id.discount);
//            descTV = itemView.findViewById(R.id.desc);
        }
    }
}
